package com.yaoweigroup.community.adapter;

import java.util.List;

import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.bitmap.BitmapDisplayConfig;
import com.yaoweigroup.community.R;
import com.yaoweigroup.community.config.Urls;
import com.yaoweigroup.community.enity.ShopDetail;
import com.yaoweigroup.community.enity.Shops;
import com.yaoweigroup.community.util.BitmapHelp;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class SubShopListAdapter extends BaseAdapter {

	private Context context;
	private List<ShopDetail> list;
	private LayoutInflater mInflater;
	private BitmapUtils bitmapUtils;
	private BitmapDisplayConfig bigPicDisplayConfig;

	public SubShopListAdapter(Context context, List<ShopDetail> list) {
		mInflater = LayoutInflater.from(context);
		this.context = context;
		this.list = list;

		bitmapUtils = BitmapHelp.getBitmapUtils(context);
		bigPicDisplayConfig = new BitmapDisplayConfig();
		bigPicDisplayConfig.setLoadFailedDrawable(context.getResources()
				.getDrawable(R.drawable.bucket_no_picture));
		bigPicDisplayConfig.setLoadingDrawable(context.getResources()
				.getDrawable(R.drawable.bucket_no_picture));
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder;
		if (convertView == null) {
			holder = new Holder();
			convertView = mInflater.inflate(R.layout.adapter_shop_detail_item,
					null);
			convertView.setTag(holder);
			holder.icon_iv = (ImageView) convertView.findViewById(R.id.icon_iv);
			holder.name_tv = (TextView) convertView.findViewById(R.id.name_tv);
			holder.price_tv = (TextView) convertView
					.findViewById(R.id.price_tv);
		} else {
			holder = (Holder) convertView.getTag();
		}
		ShopDetail detail = list.get(position);
		bitmapUtils.display(holder.icon_iv, detail.getHeadimg(),
				bigPicDisplayConfig);
		holder.name_tv.setText(detail.getName());
		holder.price_tv.setText("价格：¥" + detail.getPrice());
		return convertView;
	}

	public final class Holder {

		TextView name_tv;
		ImageView icon_iv;
		TextView price_tv;

	}

	public void setDataChange(List<ShopDetail> list) {
		this.list = list;
		notifyDataSetChanged();
	}

}
